package com.framework.common.config;

import cn.hutool.dfa.SensitiveUtil;
import com.alibaba.fastjson.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.Set;

/**
 * 敏感词初始化
 */
public class SensitiveWordsInit {

    protected static Logger logger = LoggerFactory.getLogger(SensitiveWordsInit.class);

    public static void initSensitiveWords(String strTextBadWords) {
        Set<String> set = new HashSet<>();
        try {
            JSONArray jsonArray = JSONArray.parseArray(strTextBadWords);
            for (int i = 0; i < jsonArray.size(); i++) {
                set.add(jsonArray.getString(i));
            }
            SensitiveUtil.init(set);
            logger.info("加载敏感词成功");
        } catch (Exception e) {
            logger.error("加载敏感词文件失败: " + e.getMessage());
        }

    }
}
